/**
 * Copyright (c) 2008, Andrew Carter
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are 
 * permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer. Redistributions in binary form must reproduce 
 * the above copyright notice, this list of conditions and the following disclaimer in 
 * the documentation and/or other materials provided with the distribution. Neither the 
 * name of Andrew Carter nor the names of contributors may be used to endorse or promote 
 * products derived from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.acarter.scenemonitor.dialog;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.acarter.scenemonitor.util.Util;
import com.acarter.scenemonitor.util.Constants;

/**
 * 
 * @author Andrew Carter
 */
public class AboutDlg extends JDialog {

    /**	 */
    private static final long serialVersionUID = 1L;

    /**  */
    public static final Font font = new Font("Helvetica", Font.PLAIN, 10);

    /**  */
    public static final Font boldFont = new Font("Helvetica", Font.BOLD, 11);

    /**  */
    public static final Insets insets = new Insets(1, 1, 1, 1);

    /**
     * 
     * @param
     */
    public AboutDlg(Frame parent) {

	super(parent, "About", true);

	setResizable(false);

	build();
	pack();
    }

    /**
     * 
     */
    private void build() {

	final Window window = this;

	URL imageURL = AboutDlg.class.getClassLoader().getResource(Constants.DIALOGDATAPATH + "ac.png");
	ImageIcon image = null;

	if(imageURL != null)
	    image = new ImageIcon(imageURL);

	final String acLink = "http://www.addictivecode.com";

	JLabel imageLabel = new JLabel(image);
	imageLabel.addMouseListener(new MouseListener() {

	    public void mouseClicked(MouseEvent e) {
		Util.openURL(acLink);
	    }

	    public void mouseEntered(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.HAND_CURSOR));
	    }

	    public void mouseExited(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	    }

	    public void mousePressed(MouseEvent e) {
	    }

	    public void mouseReleased(MouseEvent e) {
	    }
	});

	imageURL = AboutDlg.class.getClassLoader().getResource(Constants.DIALOGDATAPATH + "jME.png");
	ImageIcon jME = null;

	if(imageURL != null)
	    jME = new ImageIcon(imageURL);

	JLabel jMELabel = new JLabel(jME);

	JLabel title = new JLabel("Scene Monitor");
	title.setFont(boldFont);

	JLabel versionLabel = new JLabel("Version: " + Constants.VERSION);
	versionLabel.setFont(font);

	final String licenseLink = "http://www.opensource.org/licenses/bsd-license.php";

	JLabel license = new JLabel("<html><a href=\"" + licenseLink + "\">Distributed under the BSD license</a></html>");
	license.setFont(font);
	license.addMouseListener(new MouseListener() {

	    public void mouseClicked(MouseEvent e) {
		Util.openURL(licenseLink);
	    }

	    public void mouseEntered(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.HAND_CURSOR));
	    }

	    public void mouseExited(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	    }

	    public void mousePressed(MouseEvent e) {
	    }

	    public void mouseReleased(MouseEvent e) {
	    }
	});

	JLabel copyright = new JLabel("Copyright 2010 Andrew Carter, All Rights Reserved.");
	copyright.setFont(font);

	JLabel contact = new JLabel("andrew.k.carter@gmail.com");
	contact.setFont(font);

	final String googleCodeLink = "http://scenemonitor.googlecode.com";
	
	JLabel addictiveCode = new JLabel("<html><a href=\"\">" + googleCodeLink + "</a></html>");
	addictiveCode.setFont(font);
	addictiveCode.addMouseListener(new MouseListener() {

	    public void mouseClicked(MouseEvent e) {
	    	Util.openURL(googleCodeLink);
	    }

	    public void mouseEntered(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.HAND_CURSOR));
	    }

	    public void mouseExited(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	    }

	    public void mousePressed(MouseEvent e) {
	    }

	    public void mouseReleased(MouseEvent e) {
	    }
	});

	JLabel jme1 = new JLabel("Made possible by");
	jme1.setFont(font);

	JLabel jme2 = new JLabel("and the Ardor3D team and community at");
	jme2.setFont(font);

	final String link = "http://www.ardor3d.com";

	JLabel jme3 = new JLabel("<html><a href=\"\">" + link + "</a></html>");
	jme3.setFont(font);
	jme3.addMouseListener(new MouseListener() {

	    public void mouseClicked(MouseEvent e) {
		Util.openURL(link);
	    }

	    public void mouseEntered(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.HAND_CURSOR));
	    }

	    public void mouseExited(MouseEvent e) {
		window.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	    }

	    public void mousePressed(MouseEvent e) {
	    }

	    public void mouseReleased(MouseEvent e) {
	    }
	});

	JPanel about = new JPanel();
	about.setLayout(new BoxLayout(about, BoxLayout.Y_AXIS));
	about.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	about.setBackground(Color.WHITE);
	about.add(title);
	about.add(versionLabel);
	about.add(license);
	about.add(Box.createRigidArea(new Dimension(0, 10)));
	about.add(copyright);
	about.add(contact);
	about.add(addictiveCode);
	about.add(Box.createRigidArea(new Dimension(0, 12)));
	about.add(jme1);
	about.add(jMELabel);
	about.add(jme2);
	about.add(jme3);
	about.add(Box.createGlue());

	JButton ok = new JButton("OK");
	ok.setFont(boldFont);
	ok.setPreferredSize(new Dimension(50, 18));
	ok.setMargin(insets);
	ok.addActionListener(new ActionListener() {

	    public void actionPerformed(ActionEvent e) {
		setVisible(false);
		dispose();
	    }
	});

	JPanel buttonPanel = new JPanel();
	buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
	buttonPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.gray), BorderFactory
		.createEmptyBorder(10, 10, 10, 10)));
	buttonPanel.add(Box.createGlue());
	buttonPanel.add(ok);
	buttonPanel.add(Box.createGlue());

	JPanel panel = new JPanel(new BorderLayout());
	panel.add(about, BorderLayout.WEST);
	panel.add(imageLabel, BorderLayout.EAST);
	panel.add(buttonPanel, BorderLayout.SOUTH);

	setContentPane(panel);
	setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    }
}
